package middleware

import (
	"gitee.com/chenrh/finego/backends/utils"
	"github.com/kataras/iris/v12"
)

// PageIndexDataCheck 为首页提供一些数据，登录信息
func PageIndexDataCheck(ctx iris.Context) {
	ok, user := utils.UserCache(ctx)
	if !ok {
		ctx.ViewData("IsLogin", false)
		ctx.ViewData("NickName", "")
		ctx.ViewData("UserCode", "")
		ctx.ViewData("UrlFrom", ctx.RequestPath(true))

	} else {
		ctx.ViewData("IsLogin", ok)
		ctx.ViewData("NickName", user.NickName)
		ctx.ViewData("UserCode", user.UserCode)
	}
	ctx.Next()
}
